package wservice;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;

public abstract class ParamHelper {

	private static final String accessKey = "accessKey"; 
	private static final String timestamp = "timestamp";
	
	public static RequestParam getRequestParam(HttpServletRequest request) {
		//  /app/module/action
		String uri = request.getRequestURI();
		if(uri.startsWith("/")) {
			uri = uri.substring(1);
		}
		if(uri.endsWith("/")) {
			uri = uri.substring(0,uri.length()-1);
		}
		String[] uriArray = uri.split("/");
		if(uriArray.length != 3) {
			return null;
		}
		RequestParam param = new RequestParam();
		param.setApp(uriArray[0]);
		param.setModule(uriArray[1]);
		param.setAction(uriArray[2]);
		
		String ak = request.getParameter(accessKey);
		String tt = request.getParameter(timestamp);
		param.setAccessKey(ak);
		param.setTimestamp(tt);
		return param;
	}
	
	public static void main(String[] args) {
		String uri = "/app/module/action";
		if(uri.startsWith("/")) {
			uri = uri.substring(1);
		}
		if(uri.endsWith("/")) {
			uri = uri.substring(0,uri.length()-1);
		}
		String[] uriArray = uri.split("/");
		if(uriArray.length != 3) {
		}
		System.out.println(Arrays.toString(uriArray));
	}

}
